﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Base.Common.Converters
{
    /// <summary>
    /// 转换可见性
    /// </summary>
    public class ValueParmToVisbleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility tmepVisble = Visibility.Collapsed;
            if (parameter == null || value == null)
                return tmepVisble;
            tmepVisble = value.Equals(parameter) ? Visibility.Visible : Visibility.Collapsed;
            return tmepVisble;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;
            if (((Visibility)value) == Visibility.Visible)
            {
                return parameter;
            }
            else
            {
                return null;
            }
        }
    }

    /// <summary>
    /// 转换Bool
    /// </summary>
    public class ValueParmToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool tmepBool = false;
            if (parameter == null || value == null)
                return tmepBool;
            tmepBool = value.Equals(parameter) ? true : false;
            return tmepBool;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;
            if ((bool)value)
            {
                return parameter;
            }
            else
            {
                return null;
            }
        }
    }

    /// <summary>
    /// 转换Bool
    /// </summary>
    public class ValueParmToUnBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool tmepBool = false;
            if (parameter == null || value == null)
                return tmepBool;
            tmepBool = value.Equals(parameter) ? false : true;
            return tmepBool;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;
            if ((bool)value)
            {
                return parameter;
            }
            else
            {
                return null;
            }
        }
    }

    /// <summary>
    /// 是否大于0
    /// </summary>
    public class IsBigZeroConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool tmepBool = false;
            if (value == null)
                return tmepBool;
            tmepBool = value.ToString().ToInt32() > 0;
            return tmepBool;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
